﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.IO;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using cde.UserControl;

public partial class main_comm_CsvUpload : MenuPage
{
    private string land_id = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        land_id = languageCode;
    }
    protected void cmdCsvInput_Click(object sender, EventArgs e)
    {
        String filepath = fileUpload.FileName;
        if (filepath == null || filepath.Trim() == "")
        {
            // "ファイルを選択してください";
            return;
        }
        string tmpInFile =
            System.Configuration.ConfigurationManager.AppSettings["CSV_IN_PATH"] + "_in_"
            + Session.SessionID + "_" + land_id + ".csv";
        tmpInFile = System.Web.HttpContext.Current.Server.MapPath(tmpInFile);
        //保存，关闭
        if (File.Exists(tmpInFile))
        {
            File.Delete(tmpInFile);
        }
        fileUpload.PostedFile.SaveAs(tmpInFile);
        tmpInFile = tmpInFile.Replace("\\",",");
        //Session["EXCEL_IMPORT_TMPFILE"] = tmpInFile;

        StringBuilder sbr = new StringBuilder();
        sbr.AppendFormat("<script language=\"javascript\">{0}", Environment.NewLine);
        sbr.AppendFormat("opener.document.getElementById(\"hidCsvInPath\").value=\"");
        sbr.AppendFormat(tmpInFile);
        sbr.AppendFormat("\";", Environment.NewLine);
        sbr.AppendFormat("opener.document.getElementById(\"hidRefreshBtn\").click();", Environment.NewLine);
        sbr.AppendFormat("window.close();", Environment.NewLine);
        sbr.AppendFormat("</script>{0}", Environment.NewLine);
        Page.ClientScript.RegisterStartupScript(Page.GetType(), "Startup", sbr.ToString());
    }
}
